<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="packAll" name="Create Runnable Jars">
	<taskdef name="swtjar" classname="org.swtjar.ant.SWTJarTask" classpath="./lib/swtjar.jar" />

	<!--Build all executables-->
	<target name="packAll">
		<!--Eliminate the contents of the dist forlder-->
		<delete dir="./dist" />
		<mkdir dir="./dist" />
		<!--Pack the linux_64 dist file-->
		<antcall target="pack">
			<param name="dist" value="./dist/pmTrans_linux_64" />
			<param name="swt_file" value="swt-linux64-4.2.2.jar" />
			<param name="file_name" value="pmTrans_linux_64.zip" />
		</antcall>
		<!--Pack the linux_x86 dist file-->
		<antcall target="pack">
			<param name="dist" value="./dist/pmTrans_linux_x86" />
			<param name="swt_file" value="swt-linux32-4.2.2.jar" />
			<param name="file_name" value="pmTrans_linux_x86.zip" />
		</antcall>
		<!--Pack the win_64 dist file-->
		<antcall target="pack">
			<param name="dist" value="./dist/pmTrans_win_64" />
			<param name="swt_file" value="swt-win64-4.2.2.jar" />
			<param name="file_name" value="pmTrans_win_64.zip" />
		</antcall>
		<!--Pack the win_x86 dist file-->
		<antcall target="pack">
			<param name="dist" value="./dist/pmTrans_win_x86" />
			<param name="swt_file" value="swt-win32-4.2.2.jar" />
			<param name="file_name" value="pmTrans_win_x86.zip" />
		</antcall>
		<!--Pack the mac_64 dist file-->
		<antcall target="pack">
			<param name="dist" value="./dist/pmTrans_macosx_64" />
			<param name="swt_file" value="swt-osx64-4.2.2.jar" />
			<param name="file_name" value="pmTrans_macosx_64.zip" />
		</antcall>
		<!--Pack the mac_x86 dist file-->
		<antcall target="pack">
			<param name="dist" value="./dist/pmTrans_macosx_x86" />
			<param name="swt_file" value="swt-osx32-4.2.2.jar" />
			<param name="file_name" value="pmTrans_macosx_x86.zip" />
		</antcall>
		<!--Pack the allOs dist file-->
		<swtjar jarfile="./dist/pmTransAllOs.jar" targetmainclass="gui.PmTrans" swtversion="4.2.2">

			<!-- Application Classes -->
			<fileset dir="./bin" />

			<!-- Library Classes -->
			<zipfileset excludes="META-INF/*" src="lib/JNativeHook.jar" />
			<zipfileset excludes="META-INF/*" src="lib/TarsosDSP.jar" />
			<zipfileset excludes="META-INF/*" src="lib/TarsosTranscoder-1.1-bin.jar" />
			<zipfileset excludes="META-INF/*" src="lib/org.eclipse.core.commands_3.6.100.v20130515-1857.jar" />
			<zipfileset excludes="META-INF/*" src="lib/org.eclipse.equinox.common_3.6.200.v20130402-1505.jar" />
			<zipfileset excludes="META-INF/*" src="lib/org.eclipse.jface_3.9.1.v20130725-1141.jar" />

			<!-- SWT Jars -->
			<fileset excludes="META-INF/*" dir="./lib" includes="swt-*.jar" />
		</swtjar>
		<mkdir dir="./dist/pmTrans" />
		<mkdir dir="./dist/pmTrans/pmTrans" />
		<copy file="./dist/pmTransAllOs.jar" todir="./dist/pmTrans/pmTrans" />
		<delete file="./dist/pmTransAllOs.jar" />
		<zip destfile="./dist/pmTransAllOs.zip" basedir="./dist/pmTrans" />
		<delete dir="./dist/pmTrans" />
	</target>

	<!--Build the linux zipfile-->
	<target name="pack">
		<!--Create the executable jar file -->
		<mkdir dir="${dist}" />
		<jar destfile="${dist}/pmTrans.jar">
			<manifest>
				<attribute name="Main-Class" value="gui.PmTrans" />
				<attribute name="Class-Path" value=". lib/JNativeHook.jar 
					lib/TarsosDSP.jar 
					lib/TarsosTranscoder-1.1-bin.jar
					lib/org.eclipse.core.commands_3.6.100.v20130515-1857.jar 
					lib/org.eclipse.equinox.common_3.6.200.v20130402-1505.jar 
					lib/org.eclipse.jface_3.9.1.v20130725-1141.jar  
					lib/${swt_file}" />
			</manifest>
			<fileset dir="./bin" />
		</jar>
		<!--Copy the lib folder-->
		<delete dir="${dist}/lib" />
		<mkdir dir="${dist}/lib" />
		<copy file="./lib/JNativeHook.jar" todir="${dist}/lib" />
		<copy file="./lib/TarsosDSP.jar" todir="${dist}/lib" />
		<copy file="./lib/TarsosTranscoder-1.1-bin.jar" todir="${dist}/lib" />
		<copy file="./lib/org.eclipse.core.commands_3.6.100.v20130515-1857.jar" todir="${dist}/lib" />
		<copy file="./lib/org.eclipse.equinox.common_3.6.200.v20130402-1505.jar" todir="${dist}/lib" />
		<copy file="./lib/org.eclipse.jface_3.9.1.v20130725-1141.jar" todir="${dist}/lib" />
		<copy file="./lib/${swt_file}" todir="${dist}/lib" />
		<!--Create the executable script-->
		<condition property="win">
			<contains substring="win" string="${dist}" />
		</condition>
		<condition property="linux">
			<contains substring="linux" string="${dist}" />
		</condition>
		<antcall target="makeBatFile" />
		<antcall target="makeShFile" />
		<!--Create zip and remove auxilizary files-->
		<mkdir dir="./dist/pmTrans" />
		<mkdir dir="./dist/pmTrans/pmTrans" />
		<copydir dest="./dist/pmTrans/pmTrans" src="${dist}"/>
		<zip destfile="./dist/${file_name}" basedir="./dist/pmTrans" />
		<delete dir="${dist}" />
		<delete dir="./dist/pmTrans" />
	</target>
	<target name="makeBatFile" if="win">
		<echo file="${dist}/pmTrans.bat">
			java -jar pmTrans.jar
		</echo>
	</target>
	<target name="makeShFile" if="linux">
		<echo file="${dist}/pmTrans.sh">
			#!/bin/bash
			java -jar pmTrans.jar
		</echo>
	</target>
</project>
